// 引用百度地图微信小程序JSAPI模块 
// var bmap = require('../../libs/bmap-wx.js');
var QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
var qqmapsdk;
var app=getApp();
let city=app.city;
Page({
  data: {
    sugData: [],
    hasresult:true,
  },
  // 绑定input输入 
  bindKeyInput: function (e) {
    var that = this;
    var value=e.detail.value;
    
    qqmapsdk = new QQMapWX({
      key: '2WOBZ-DKPCV-2MAPX-U4K62-AASUE-BWBMT'
    });
    if(value){
      qqmapsdk.getSuggestion({
        keyword: value,
        region: city,
        page_size: 20,
        success: function (data) {

          var length = data.data.length;
          console.log("搜索数目"+length)
          if (value.length == 0) {
            that.setData({
              sugData: '',
              hasresult: true
            });
          } else {
            var sugData = '';
            if (length > 0) {
              console.log(data.data)

              that.setData({
                sugData: data.data,
                hasresult: true
              });

            } else {
              that.setData({
               
                hasresult: false
              });


            }
          }

        },
        fail: function (err) {
          console.log(err);
          that.setData({
            sugData: '',
            hasresult: false
          })
        }
      })
    }else{
      that.setData({
        sugData: '',
        hasresult: true
      });
    }
    


    //新建百度地图对象 
    // var BMap = new bmap.BMapWX({
    //   ak: 'bzQsfmU86UsaqMOeZzXFrjbkVAUKcVYW'
    // });
    // var fail = function (data) {
    //   console.log(data)
    // };
    // var success = function (data) {
    //   console.log(data);
    //   var sugData = '';
     
    //   that.setData({
    //     sugData: data.result
    //   });
    // }
   // 发起suggestion检索请求 
    // BMap.suggestion({
    //   query: e.detail.value,
    //   region: city,
    //   city_limit: true,
    //   fail: fail,
    //   success: success
    // });
  },
  catchaddr:function(e){
      var that=this;
      var title=e.currentTarget.dataset.title;
      var map_add=e.currentTarget.dataset.address;
      var jingwei=e.currentTarget.dataset.jingwei;
      console.log("************e*****************");
      console.log(e)
    
    wx.setStorage({
      key: "title_key",
       data: e.currentTarget.dataset.title
      // data: e.currentTarget.dataset.address
    })
    wx.setStorage({
      key: "map_add_key",
      data: e.currentTarget.dataset.address
      // data: e.currentTarget.dataset.title
    })
    console.log(e.currentTarget.dataset.address)
    wx.setStorage({
      key: "jingwei_key",
      data: e.currentTarget.dataset.jingwei
    })
    wx.getStorage({
      key: 'lujing',
      success: function(res) {
        console.log("***getstorage******");
        console.log(res.data)
        // wx.redirectTo({
        //   url: '/pages/' + res.data,
        // })
        wx.navigateBack({
          delta:1
        })
       
      },
    })
     
    //  wx.request({
    //    url: "http://ydsuda.youdang.xin/appss/value/index",
    //    data:{
    //      map_add:map_addr,
    //      jingwei:jingwei
    //    },
    //    success:function(res){
    //      console.log("***************success************");
    //      console.log(res);
        
    //    },
    //    fail:function(err){
    //      console.log(err)
    //    }
   
    //  })
   
  },


}) 